package com.ruoyi.activity.service.impl;

import java.util.Collections;
import java.util.List;

import com.ruoyi.activity.mapper.WebOrganizersMapper;
import com.ruoyi.activity.service.IWebOrganizersService;
import com.ruoyi.model.organizers.WebOrganizers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 主办方Service业务层处理
 *
 * @author 张怀秋
 * @date 2024-08-02
 */
@Service
public class WebOrganizersServiceImpl implements IWebOrganizersService {
    @Autowired
    private WebOrganizersMapper webOrganizersMapper;

    @Resource
    private RedisTemplate<Object, Object> redisTemplate;

    /**
     * 查询主办方
     *
     * @param id 主办方主键
     * @return 主办方
     */
    @Override
    public WebOrganizers selectWebOrganizersById(Long id) {
        return webOrganizersMapper.selectWebOrganizersById(id);
    }

    /**
     * 查询主办方列表
     *
     * @param webOrganizers 主办方
     * @return 主办方
     */
    @Override
    public List<WebOrganizers> selectWebOrganizersList(WebOrganizers webOrganizers) {
        return webOrganizersMapper.selectWebOrganizersList(webOrganizers);
    }

    /**
     * 新增主办方
     *
     * @param webOrganizers 主办方
     * @return 结果
     */
    @Override
    public int insertWebOrganizers(WebOrganizers webOrganizers) {
        redisTemplate.delete("organizers");
        return webOrganizersMapper.insertWebOrganizers(webOrganizers);
    }

    /**
     * 修改主办方
     *
     * @param webOrganizers 主办方
     * @return 结果
     */
    @Override
    public int updateWebOrganizers(WebOrganizers webOrganizers) {
        redisTemplate.delete("organizers");
        return webOrganizersMapper.updateWebOrganizers(webOrganizers);
    }

    /**
     * 批量删除主办方
     *
     * @param ids 需要删除的主办方主键
     * @return 结果
     */
    @Override
    public int deleteWebOrganizersByIds(Long[] ids) {
        redisTemplate.delete("organizers");
        return webOrganizersMapper.deleteWebOrganizersByIds(ids);
    }

    /**
     * 删除主办方信息
     *
     * @param id 主办方主键
     * @return 结果
     */
    @Override
    public int deleteWebOrganizersById(Long id) {
        redisTemplate.delete("organizers");
        return webOrganizersMapper.deleteWebOrganizersById(id);
    }

    /**
     * 查询主办方，用于发布竞赛，活动等做检索
     *
     * @return List<WebOrganizers>
     */
    @Override
    @Cacheable(value = "organizers", key = "'getList'")
    public List<WebOrganizers> getList() {
        return webOrganizersMapper.selectList(null);
    }
}
